/**
 * Language.java
 *
 * Copyright (C) 2007,  Richard Midwinter
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.google.api.me.translate;

import java.util.Vector;

/**
 * Defines language information for the Google Translate API.
 *
 * @author Richard Midwinter
 * @author alosii
 * @author bjkuczynski
 */
public final class Language {


    public static final Language AUTO_DETECT=new Language("");
    public static final Language AFRIKAANS=new Language("af");
    public static final Language ALBANIAN=new Language("sq");
    public static final Language AMHARIC=new Language("am");
    public static final Language ARABIC=new Language("ar");
    public static final Language ARMENIAN=new Language("hy");
    public static final Language AZERBAIJANI=new Language("az");
    public static final Language BASQUE=new Language("eu");
    public static final Language BELARUSIAN=new Language("be");
    public static final Language BENGALI=new Language("bn");
    public static final Language BIHARI=new Language("bh");
    public static final Language BULGARIAN=new Language("bg");
    public static final Language BURMESE=new Language("my");
    public static final Language CATALAN=new Language("ca");
    public static final Language CHEROKEE=new Language("chr");
    public static final Language CHINESE=new Language("zh");
    public static final Language CHINESE_SIMPLIFIED=new Language("zh-CN");
    public static final Language CHINESE_TRADITIONAL=new Language("zh-TW");
    public static final Language CROATIAN=new Language("hr");
    public static final Language CZECH=new Language("cs");
    public static final Language DANISH=new Language("da");
    public static final Language DHIVEHI=new Language("dv");
    public static final Language DUTCH=new Language("nl");
    public static final Language ENGLISH=new Language("en");
    public static final Language ESPERANTO=new Language("eo");
    public static final Language ESTONIAN=new Language("et");
    public static final Language FILIPINO=new Language("tl");
    public static final Language FINNISH=new Language("fi");
    public static final Language FRENCH=new Language("fr");
    public static final Language GALACIAN=new Language("gl");
    public static final Language GEORGIAN=new Language("ka");
    public static final Language GERMAN=new Language("de");
    public static final Language GREEK=new Language("el");
    public static final Language GUARANI=new Language("gn");
    public static final Language GUJARATI=new Language("gu");
    public static final Language HEBREW=new Language("iw");
    public static final Language HINDI=new Language("hi");
    public static final Language HUNGARIAN=new Language("hu");
    public static final Language ICELANDIC=new Language("is");
    public static final Language INDONESIAN=new Language("id");
    public static final Language INUKTITUT=new Language("iu");
    public static final Language IRISH=new Language("ga");
    public static final Language ITALIAN=new Language("it");
    public static final Language JAPANESE=new Language("ja");
    public static final Language KANNADA=new Language("kn");
    public static final Language KAZAKH=new Language("kk");
    public static final Language KHMER=new Language("km");
    public static final Language KOREAN=new Language("ko");
    public static final Language KURDISH=new Language("ku");
    public static final Language KYRGYZ=new Language("ky");
    public static final Language LAOTHIAN=new Language("lo");
    public static final Language LATVIAN=new Language("lv");
    public static final Language LITHUANIAN=new Language("lt");
    public static final Language MACEDONIAN=new Language("mk");
    public static final Language MALAY=new Language("ms");
    public static final Language MALAYALAM=new Language("ml");
    public static final Language MALTESE=new Language("mt");
    public static final Language MARATHI=new Language("mr");
    public static final Language MONGOLIAN=new Language("mn");
    public static final Language NEPALI=new Language("ne");
    public static final Language NORWEGIAN=new Language("no");
    public static final Language ORIYA=new Language("or");
    public static final Language PASHTO=new Language("ps");
    public static final Language PERSIAN=new Language("fa");
    public static final Language POLISH=new Language("pl");
    public static final Language PORTUGUESE=new Language("pt");
    public static final Language PUNJABI=new Language("pa");
    public static final Language ROMANIAN=new Language("ro");
    public static final Language RUSSIAN=new Language("ru");
    public static final Language SANSKRIT=new Language("sa");
    public static final Language SERBIAN=new Language("sr");
    public static final Language SINDHI=new Language("sd");
    public static final Language SINHALESE=new Language("si");
    public static final Language SLOVAK=new Language("sk");
    public static final Language SLOVENIAN=new Language("sl");
    public static final Language SPANISH=new Language("es");
    public static final Language SWAHILI=new Language("sw");
    public static final Language SWEDISH=new Language("sv");
    public static final Language TAJIK=new Language("tg");
    public static final Language TAMIL=new Language("ta");
    public static final Language TAGALOG=new Language("tl");
    public static final Language TELUGU=new Language("te");
    public static final Language THAI=new Language("th");
    public static final Language TIBETAN=new Language("bo");
    public static final Language TURKISH=new Language("tr");
    public static final Language UKRANIAN=new Language("uk");
    public static final Language URDU=new Language("ur");
    public static final Language UZBEK=new Language("uz");
    public static final Language UIGHUR=new Language("ug");
    public static final Language VIETNAMESE=new Language("vi");
    public static final Language WELSH=new Language("cy");
    public static final Language YIDDISH=new Language("yi");

    private static Vector values;
// XXX: this static init crashes
//    static{
//        values.addElement(AUTO_DETECT);
//        values.addElement(AFRIKAANS);
//        values.addElement(ALBANIAN);
//        values.addElement(AMHARIC);
//        values.addElement(ARABIC);
//        values.addElement(ARMENIAN);
//        values.addElement(AZERBAIJANI);
//        values.addElement(BASQUE);
//        values.addElement(BELARUSIAN);
//        values.addElement(BENGALI);
//        values.addElement(BIHARI);
//        values.addElement(BULGARIAN);
//        values.addElement(BURMESE);
//        values.addElement(CATALAN);
//        values.addElement(CHEROKEE);
//        values.addElement(CHINESE);
//        values.addElement(CHINESE_SIMPLIFIED);
//        values.addElement(CHINESE_TRADITIONAL);
//        values.addElement(CROATIAN);
//        values.addElement(CZECH);
//        values.addElement(DANISH);
//        values.addElement(DHIVEHI);
//        values.addElement(DUTCH);
//        values.addElement(ENGLISH);
//        values.addElement(ESPERANTO);
//        values.addElement(ESTONIAN);
//        values.addElement(FILIPINO);
//        values.addElement(FINNISH);
//        values.addElement(FRENCH);
//        values.addElement(GALACIAN);
//        values.addElement(GEORGIAN);
//        values.addElement(GERMAN);
//        values.addElement(GREEK);
//        values.addElement(GUARANI);
//        values.addElement(GUJARATI);
//        values.addElement(HEBREW);
//        values.addElement(HINDI);
//        values.addElement(HUNGARIAN);
//        values.addElement(ICELANDIC);
//        values.addElement(INDONESIAN);
//        values.addElement(INUKTITUT);
//        values.addElement(IRISH);
//        values.addElement(ITALIAN);
//        values.addElement(JAPANESE);
//        values.addElement(KANNADA);
//        values.addElement(KAZAKH);
//        values.addElement(KHMER);
//        values.addElement(KOREAN);
//        values.addElement(KURDISH);
//        values.addElement(KYRGYZ);
//        values.addElement(LAOTHIAN);
//        values.addElement(LATVIAN);
//        values.addElement(LITHUANIAN);
//        values.addElement(MACEDONIAN);
//        values.addElement(MALAY);
//        values.addElement(MALAYALAM);
//        values.addElement(MALTESE);
//        values.addElement(MARATHI);
//        values.addElement(MONGOLIAN);
//        values.addElement(NEPALI);
//        values.addElement(NORWEGIAN);
//        values.addElement(ORIYA);
//        values.addElement(PASHTO);
//        values.addElement(PERSIAN);
//        values.addElement(POLISH);
//        values.addElement(PORTUGUESE);
//        values.addElement(PUNJABI);
//        values.addElement(ROMANIAN);
//        values.addElement(RUSSIAN);
//        values.addElement(SANSKRIT);
//        values.addElement(SERBIAN);
//        values.addElement(SINDHI);
//        values.addElement(SINHALESE);
//        values.addElement(SLOVAK);
//        values.addElement(SLOVENIAN);
//        values.addElement(SPANISH);
//        values.addElement(SWAHILI);
//        values.addElement(SWEDISH);
//        values.addElement(TAJIK);
//        values.addElement(TAMIL);
//        values.addElement(TAGALOG);
//        values.addElement(TELUGU);
//        values.addElement(THAI);
//        values.addElement(TIBETAN);
//        values.addElement(TURKISH);
//        values.addElement(UKRANIAN);
//        values.addElement(URDU);
//        values.addElement(UZBEK);
//        values.addElement(UIGHUR);
//        values.addElement(VIETNAMESE);
//        values.addElement(WELSH);
//        values.addElement(YIDDISH);
//    }

    /**
     * Google's String representation of this language.
     */
    private final String language;

    /**
     * Enum constructor.
     * @param pLanguage The language identifier.
     */
    private Language(final String pLanguage){
        language = pLanguage;
    }

    private static Vector values(){
        values = values == null ? new Vector() : values;
        values.addElement(AUTO_DETECT);
        values.addElement(AFRIKAANS);
        values.addElement(ALBANIAN);
        values.addElement(AMHARIC);
        values.addElement(ARABIC);
        values.addElement(ARMENIAN);
        values.addElement(AZERBAIJANI);
        values.addElement(BASQUE);
        values.addElement(BELARUSIAN);
        values.addElement(BENGALI);
        values.addElement(BIHARI);
        values.addElement(BULGARIAN);
        values.addElement(BURMESE);
        values.addElement(CATALAN);
        values.addElement(CHEROKEE);
        values.addElement(CHINESE);
        values.addElement(CHINESE_SIMPLIFIED);
        values.addElement(CHINESE_TRADITIONAL);
        values.addElement(CROATIAN);
        values.addElement(CZECH);
        values.addElement(DANISH);
        values.addElement(DHIVEHI);
        values.addElement(DUTCH);
        values.addElement(ENGLISH);
        values.addElement(ESPERANTO);
        values.addElement(ESTONIAN);
        values.addElement(FILIPINO);
        values.addElement(FINNISH);
        values.addElement(FRENCH);
        values.addElement(GALACIAN);
        values.addElement(GEORGIAN);
        values.addElement(GERMAN);
        values.addElement(GREEK);
        values.addElement(GUARANI);
        values.addElement(GUJARATI);
        values.addElement(HEBREW);
        values.addElement(HINDI);
        values.addElement(HUNGARIAN);
        values.addElement(ICELANDIC);
        values.addElement(INDONESIAN);
        values.addElement(INUKTITUT);
        values.addElement(IRISH);
        values.addElement(ITALIAN);
        values.addElement(JAPANESE);
        values.addElement(KANNADA);
        values.addElement(KAZAKH);
        values.addElement(KHMER);
        values.addElement(KOREAN);
        values.addElement(KURDISH);
        values.addElement(KYRGYZ);
        values.addElement(LAOTHIAN);
        values.addElement(LATVIAN);
        values.addElement(LITHUANIAN);
        values.addElement(MACEDONIAN);
        values.addElement(MALAY);
        values.addElement(MALAYALAM);
        values.addElement(MALTESE);
        values.addElement(MARATHI);
        values.addElement(MONGOLIAN);
        values.addElement(NEPALI);
        values.addElement(NORWEGIAN);
        values.addElement(ORIYA);
        values.addElement(PASHTO);
        values.addElement(PERSIAN);
        values.addElement(POLISH);
        values.addElement(PORTUGUESE);
        values.addElement(PUNJABI);
        values.addElement(ROMANIAN);
        values.addElement(RUSSIAN);
        values.addElement(SANSKRIT);
        values.addElement(SERBIAN);
        values.addElement(SINDHI);
        values.addElement(SINHALESE);
        values.addElement(SLOVAK);
        values.addElement(SLOVENIAN);
        values.addElement(SPANISH);
        values.addElement(SWAHILI);
        values.addElement(SWEDISH);
        values.addElement(TAJIK);
        values.addElement(TAMIL);
        values.addElement(TAGALOG);
        values.addElement(TELUGU);
        values.addElement(THAI);
        values.addElement(TIBETAN);
        values.addElement(TURKISH);
        values.addElement(UKRANIAN);
        values.addElement(URDU);
        values.addElement(UZBEK);
        values.addElement(UIGHUR);
        values.addElement(VIETNAMESE);
        values.addElement(WELSH);
        values.addElement(YIDDISH);
        return values;
    }

    /**
     * 
     * @param pLanguage
     * @return
     */
    public static Language fromString(final String pLanguage){
        Vector languages = values();
        for (int i=0; languages.size()>0;i++) {
            if (pLanguage.equals(languages.elementAt(i).toString())) {
                return (Language)languages.elementAt(i);
            }

        }
	return null;
    }
    
    /**
     * @Override
     * Returns the String representation of this language.
     * @return The String representation of this language.
     */
    public String toString() {
            return language;
    }
}
